package com.oocl.probability;

public class Probability {
	public int getRandom(int x, int y, int a[], double b[]){
		int w = (int)(Math.random()*(y - x + 1)) + x;
		int m = 100000;
		double p = 1.0/(y-x+1);
		int container = -1;
		int temps = (int)(Math.random()*m) + y;
		double nn[] = new double[a.length];
		int[] mm = new int[a.length];
		for(int k = 0; k < a.length; k++){	
			container = -1;
			if(w == a[k]){								
				return a[k];
			}
			nn[k] = (b[k] - p) / (1 - p);   			
			mm[k] = (int)(nn[k] * m);
		}
		for(int i = 0; i < a.length; i++){	
			int tmp = y;								
			for(int j = 0; j < a.length; j++){
				tmp += mm[j];
				if(temps <= tmp){
					container = a[j];
					break;
				}
			}
			if(container != -1 ) return container;
		}
		return w;
	}
}
